package net.cooltain.warhammer.running.window.panel;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JLabel;

import net.cooltain.warhammer.framework.constant.ConstantCardRace;
import net.cooltain.warhammer.running.entity.CapitalAreaZone;
import net.cooltain.warhammer.running.entity.MotionPlayerZone;
import net.cooltain.warhammer.running.window.MainFrame;

/**
 * 默认规则：双方都可以看到对方的弃牌堆的每一张卡片
 * @author cooltian
 *
 */
public class CapitalLabel extends JLabel implements MouseListener {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2045966061927030692L;
	
	private MotionPlayerZone player ; 	// 显示这个卡片的玩家,不一定是拥有卡片的人
	private int              capitalType; // 首都类型
	private CapitalAreaZone  capitalZone; // 卡牌堆
	private BufferedImage    capitalImage;// 缓存的图片
	private static final double ROTATE_180 = Math.toRadians(180);
	
	/**
	 * 
	 * @param player 需要显示这个首都区域的玩家,不一定是主评委会首都区域的拥有者，也有可能是对手的
	 * @param capitalZone 首都区域的卡片
	 * @param capitalType 首都区域的类型
	 */
	public CapitalLabel(MotionPlayerZone player,CapitalAreaZone capitalZone,int capitalType) {
		super();
		this.capitalZone = capitalZone;
		this.capitalType = capitalType ;
		this.player = player;
		try {
			String capPicPath = ConstantCardRace.mapRaceCapitalFile.get(capitalType);
			capitalImage = ImageIO.read(new File(capPicPath));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		int currentX = (this.getWidth()-MainFrame.CAPITAL_BG_W)/2 ;
		int currentY = (this.getHeight()-MainFrame.CAPITAL_BG_H)/2 ;
		if(! player.capitalZone.equals(capitalZone)){
			Graphics2D g2D = (Graphics2D)g;
			g2D.rotate(ROTATE_180, this.getWidth()/2, this.getHeight()/2);			
		}
		g.drawImage(capitalImage,currentX, currentY, MainFrame.CAPITAL_BG_W, MainFrame.CAPITAL_BG_H, null);
	}
	
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
	}
	
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
	}
	
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

}
